package org.apache.flink.runtime.cleanup;

import org.apache.flink.api.common.ConsumerID;
import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;

import java.util.concurrent.Executor;

/**
 * {@code ResourceCleanerFactory} provides methods to create {@link ResourceCleaner} for local and
 * global cleanup.
 *
 * @see GloballyCleanableResource
 * @see LocallyCleanableResource
 */
public interface ResourceCleanerFactory {

    /**
     * Creates {@link ResourceCleaner} that initiates {@link
     * LocallyCleanableResource#localCleanupAsync(ConsumerID, Executor)} calls.
     *
     * @param mainThreadExecutor Used for validating that the {@link
     *     LocallyCleanableResource#localCleanupAsync(ConsumerID, Executor)} is called from the main
     *     thread.
     */
    ResourceCleaner createLocalResourceCleaner(ComponentMainThreadExecutor mainThreadExecutor);

    /**
     * Creates {@link ResourceCleaner} that initiates {@link
     * GloballyCleanableResource#globalCleanupAsync(ConsumerID, Executor)} calls.
     *
     * @param mainThreadExecutor Used for validating that the {@link
     *     GloballyCleanableResource#globalCleanupAsync(ConsumerID, Executor)} is called from the main
     *     thread.
     */
    ResourceCleaner createGlobalResourceCleaner(ComponentMainThreadExecutor mainThreadExecutor);
}
